用java寫一個收益表
package com.example.smallchange;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
public class SmallChangeSys {
/*
* Start with display board
*
*/
public static void main(String[] args) {
//define variable
boolean loop = true;
Scanner scanner = new Scanner(System.in);
String key = "";
String details="------------Detailed statement of accounts---------------";
//income detail
double money = 0;
double balance = 0;
Date date = null; //java.util.Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
do{
System.out.println("\n===========SmallChange===========");
System.out.println("\t\t\t1. Detailed statement of accounts");
System.out.println("\t\t\t2. Income");
System.out.println("\t\t\t3. Cost");
System.out.println("\t\t\t4. Exit");
System.out.print("Please choose(1-4) :");
key = scanner.next();
//Use Switch case control
switch(key){
case "1":
System.out.println(details);
break;
case "2":
System.out.print("Detail of Income 1");
money=scanner.nextDouble();
//money value must be positive number
balance +=money;
//output detail of balance
date = new Date();//get date
details +="\nBalance\t"+money+"\t"+sdf.format(date)+"\t"+balance;
break;
case "3":
System.out.println("3. Cost");
break;
case "4":
System.out.println("4. Exit");
loop=false;
break;
default:
System.out.println("Error,Choose again");
break;
}
}while (loop);
System.out.println("SmallChange closed");
}
}
Result :
[寫到一半]